Telegram Group & Telegram Channel
🗃 Работа с файлами и файловой системой в C++17

Хочешь получить список файлов в папке? std::filesystem предоставляет удобные итераторы для обхода директории. Особенно полезно при создании загрузчиков ассетов, инструментов или скриптов, работающих с файлами.


✏️ Решение:

1. заголовочный файл <filesystem>
2. Используй directory_iterator для обхода содержимого папки
3. Проверь тип объекта (файл, директория и т.д.), если нужно отфильтровать только файлы

#include <iostream>
#include <filesystem>

namespace fs = std::filesystem;

int main() {
std::string path = "."; // текущая директория

for (const auto& entry : fs::directory_iterator(path)) {
if (fs::is_regular_file(entry)) {
std::cout << "Файл: " << entry.path() << std::endl;
}
else if (fs::is_directory(entry)) {
std::cout << "Папка: " << entry.path() << std::endl;
}
}

return 0;
}



⚠️ Возможные ошибки:

- Подключение <experimental/filesystem> вместо стандартного <filesystem> (устарело в C++17)
- Отсутствие обработки исключений — доступ к некоторым директориям может быть запрещён


Совет:

- Добавь try-catch вокруг итератора, если работаешь с произвольными путями
- Также удобно фильтровать файлы по расширению:
if (entry.path().extension() == ".cpp")



Библиотека C/C++ разработчика #буст
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/cppproglib/5761
Create:
Last Update:

🗃 Работа с файлами и файловой системой в C++17

Хочешь получить список файлов в папке? std::filesystem предоставляет удобные итераторы для обхода директории. Особенно полезно при создании загрузчиков ассетов, инструментов или скриптов, работающих с файлами.


✏️ Решение:

1. заголовочный файл <filesystem>
2. Используй directory_iterator для обхода содержимого папки
3. Проверь тип объекта (файл, директория и т.д.), если нужно отфильтровать только файлы

#include <iostream>
#include <filesystem>

namespace fs = std::filesystem;

int main() {
std::string path = "."; // текущая директория

for (const auto& entry : fs::directory_iterator(path)) {
if (fs::is_regular_file(entry)) {
std::cout << "Файл: " << entry.path() << std::endl;
}
else if (fs::is_directory(entry)) {
std::cout << "Папка: " << entry.path() << std::endl;
}
}

return 0;
}



⚠️ Возможные ошибки:

- Подключение <experimental/filesystem> вместо стандартного <filesystem> (устарело в C++17)
- Отсутствие обработки исключений — доступ к некоторым директориям может быть запрещён


Совет:

- Добавь try-catch вокруг итератора, если работаешь с произвольными путями
- Также удобно фильтровать файлы по расширению:
if (entry.path().extension() == ".cpp")



Библиотека C/C++ разработчика #буст

BY Библиотека C/C++ разработчика | cpp, boost, qt




Share with your friend now:
tg-me.com/cppproglib/5761

View MORE
Open in Telegram


Библиотека C C разработчика | cpp boost qt Telegram | DID YOU KNOW?

Date: |

Telegram Gives Up On Crypto Blockchain Project

Durov said on his Telegram channel today that the two and a half year blockchain and crypto project has been put to sleep. Ironically, after leaving Russia because the government wanted his encryption keys to his social media firm, Durov’s cryptocurrency idea lost steam because of a U.S. court. “The technology we created allowed for an open, free, decentralized exchange of value and ideas. TON had the potential to revolutionize how people store and transfer funds and information,” he wrote on his channel. “Unfortunately, a U.S. court stopped TON from happening.”

To pay the bills, Mr. Durov is issuing investors $1 billion to $1.5 billion of company debt, with the promise of discounted equity if the company eventually goes public, the people briefed on the plans said. He has also announced plans to start selling ads in public Telegram channels as soon as later this year, as well as offering other premium services for businesses and users.

Библиотека C C разработчика | cpp boost qt from tw


Telegram Библиотека C/C++ разработчика | cpp, boost, qt
FROM USA